package com.sneakxy.cloudbase.platform.config;

import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.logging.log4j.core.util.IOUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sneakxy.cloudbase.platform.bean.UEditorSetting;

@Configuration
public class UEditorConfig {

	@Bean
	@ConfigurationProperties(prefix="ueditor")
	public UEditorSetting ueditorSetting() {
		return new UEditorSetting();
	}
	
	@Bean
	public JSONObject ueditorJsonConfig(UEditorSetting ueditorSetting) throws IOException {
		InputStreamReader reader = new InputStreamReader(new ClassPathResource("config.json").getInputStream());
		JSONObject json = (JSONObject) JSON.parse(IOUtils.toString(reader));
		reader.close();
		return json;
	}
	
}
